define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'trades/assets/card/index' + location.search,
                    add_url: 'trades/assets/card/add',
                  //  edit_url: 'trades/assets/card/edit',
                   // del_url: 'trades/assets/card/del',
                    multi_url: 'trades/assets/card/multi',
                    import_url: 'trades/assets/card/import',
                    table: 'account_card',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'card_username', title: __('Card_username'), align: 'left', operate: 'LIKE %...%', placeholder: '模糊搜索,*表示任意字符'},
                        {field: 'bank_account', title: __('Bank_account'), operate: 'LIKE'},
                        {field: 'card_type', title: __('Card_type')},
                        {field: 'bank_mobile', title: __('Bank_mobile')},
                       // {field: 'is_success', title: __('Is_success')},
                        {field: 'is_success_text', title: __('Is_success'), operate: false,formatter:function(value,row){

                                if (row['is_success'] == 1)
                                {
                                    return '<span style="color:yellowgreen">'+value+'</span>';
                                }else{
                                    return '<span style="color:blue">'+value+'</span>';
                                }

                            }
                        },
                       // {field: 'is_default', title: __('Is_default')},
                        {field: 'is_default_text', title: __('Is_default'), operate: false,formatter:function(value,row){

                                if (row['is_default'] == 1)
                                {
                                    return '<span style="color:yellowgreen">'+value+'</span>';
                                }else{
                                    return '<span style="color:blue">'+value+'</span>';
                                }

                            }
                        },
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            buttons: [
                                {
                                    name: 'ajax',
                                    text: function(row){
                                        if(row['is_default']==1) {
                                            return '解除提现账户';
                                        }

                                        else{
                                            return '设置为默认提现账户';
                                        }

                                    },
                                    title: __('发送请求'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-magic',
                                    url: 'trades/assets/card/detail?ids={ids}&is_default={is_default}',
                                    confirm: '确认发送操作请求？',
                                    // hidden:function(row){
                                    //     if(row['is_default'] == 1){
                                    //         return true;
                                    //     }
                                    // },
                                    success: function (data, ret) {
                                        //Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        //如果需要阻止成功提示，则必须使用return false;
                                        table.bootstrapTable('refresh',{});
                                        return false;

                                    },
                                    error: function (data, ret) {
                                        //console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                                {
                                    name: 'ajax',
                                    text: function(row){
                                        if(row['is_success']==1) {
                                            return '解除绑定';
                                        }

                                        else{
                                            return '设置绑定账户';
                                        }

                                    },

                                    title: __('发送请求'),
                                    classname: 'btn btn-info btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-magic',
                                    url: 'trades/assets/card/detail?ids={ids}&is_success={is_success}',
                                    confirm: '确认发送操作请求？',
                                    // hidden:function(row){
                                    //     if(row['is_success'] == 1){
                                    //         return true;
                                    //     }
                                    // },
                                    success: function (data, ret) {
                                        //Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        //如果需要阻止成功提示，则必须使用return false;
                                        table.bootstrapTable('refresh',{});
                                        return false;

                                    },
                                    error: function (data, ret) {
                                        //console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                }
                        ],
                            table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});